package 笔试;

import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;

public class 笔试360 {
    static final int M=13;
    static int k=0;
    public static void main(String[] args) {

        第一遍();



    }
    private static  int getCount(int n) { //计算个数
        int s1=1,s2=1;
        for (int i = 0; i < n; i++) {
            s1*=(2*n-i);
            s2*=(n-i);
        }
        return s1/(s2*(n+1));

    }

    private static void 第一遍() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dp(0,1,n,0L);
        System.out.println(k);
//        System.out.println(getCount(n));
    }


    private static void dp(long stack,int c2,int c3,long s) {
        //
        if(c2>c3){
            if(stack==0){
                System.out.println(s);
                k++;
                return;
            }else {
                while (stack!=0){
                    s=s*10+stack%10;
                    stack/=10;
                }
                System.out.println(s);
                k++;
                return;
            }
        }
        if(stack==0){
            stack=stack*10+c2;
            c2++;
            dp(stack,c2,c3,s);
        }else{
            stack=stack*10+c2;
            c2++;
            dp(stack,c2,c3,s);

            c2--;
            stack/=10;
            s=s*10+stack%10;
            stack/=10;
            dp(stack,c2,c3,s);
        }
        return;
    }

    private static void er() {
        Scanner sc = new Scanner(System.in);
        String[] a= sc.nextLine().split(" ");
        int[] n = new int[3];
        n[0]=Integer.valueOf(a[0]);
        n[1]=Integer.valueOf(a[1]);
        n[2]=Integer.valueOf(a[2]);
        ArrayList<HashSet<String>> l = new ArrayList<>();
        for (int i=0;i<3;i++){
            String[] s1= sc.nextLine().split(" ");
            HashSet<String> h = new HashSet<>();
            for(int j=0;j<n[i];j++){
                h.add(s1[j]);
            }
            l.add(h);
        }
        int z = Integer.valueOf(sc.nextLine());
        for(int i=0;i<z;i++){
            String[] s1= sc.nextLine().split(" ");
            int zz=0,ww=0,bb=0,zzz=0;
            for (int j=0;j<s1.length;j++){
                if(l.get(0).contains(s1[j])){
                    if(ww==0){
                        zz++;
                    }else{
                        System.out.println("NO");
                        zzz=1;
                        break;
                    }
                }else if(l.get(1).contains(s1[j])){
                    if(zz==0||ww!=0){
                        System.out.println("NO");
                        zzz=1;
                        break;
                    }else {
                        ww++;
                    }
                }else if(l.get(2).contains(s1[j])){
                    if(zz==0||ww==0){
                        System.out.println("NO");
                        zzz=1;
                        break;
                    }else {
                        bb++;
                    }
                }else {
                    System.out.println("NO");
                    zzz=1;
                    break;
                }
            }
            if(zzz==0){
                System.out.println("YES");
            }

        }
    }

    private static void diyiti() {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        int a=0,t=0,k=0;
        for(int i=0;i<s1.length();i++){
            if(s1.charAt(i)!=s2.charAt(i)){
                k++;
            }
            if(s1.charAt(i)=='A'){
                a++;
            }else {
                t++;
            }
            if(s2.charAt(i)=='A'){
                a--;
            }else {
                t--;
            }
        }
        a=Math.abs(a);
        System.out.println((k-a)/2+a);
    }
}
